home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 001-100 / 001-025 / 008 / src / hack.trap.c < prev    next >
C/C++ Source or Header  |  1995-03-17  |  9KB  |  367 lines

  1. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  2. /* hack.trap.c version 1.0.1 - added dotele(); */
  3.  
  4. #include   "hack.h"
  5. #include   "def.trap.h"
  6.  
  7. extern struct monst *makemon();
  8.  
  9. char vowels[] = "aeiou";
  10.  
  11. char *traps[] = {
  12.    " bear trap",
  13.    "n arrow trap",
  14.    " dart trap",
  15.    " trapdoor",
  16.    " teleportation trap",
  17.    " pit",
  18.    " sleeping gas trap",
  19.    " piercer",
  20.    " mimic"
  21. };
  22.  
  23. dotrap(trap) register struct gen *trap; {
  24.    nomul(0);
  25.    if(trap->gflag&SEEN && !rn2(5))
  26.         pline("You escape a%s.",traps[trap->gflag & TRAPTYPE]);
  27.    else {
  28.       trap->gflag |= SEEN;
  29.         switch(trap->gflag & TRAPTYPE) {
  30.       case SLP_GAS_TRAP:
  31.          pline("A cloud of gas puts you to sleep!");
  32.          nomul(-rnd(25));
  33.          break;
  34.       case BEAR_TRAP:
  35.          if(Levitation) {
  36.             pline("You float over a bear trap.");
  37.             break;
  38.          }
  39.          u.utrap = 4 + rn2(4);
  40.          u.utraptype = TT_BEARTRAP;
  41.          pline("A bear trap closes on your foot!");
  42.          break;
  43.       case PIERC:
  44.          deltrap(trap);
  45.          if(makemon(PM_PIERC,u.ux,u.uy)) {
  46.            pline("A piercer suddenly drops from the ceiling!");
  47.            if(uarmh)
  48.             pline("Its blow glances off your helmet.");
  49.            else
  50.             (void) thitu(3,d(4,6),"falling piercer");
  51.          }
  52.          break;
  53.       case ARROW_TRAP:
  54.          pline("An arrow shoots out at you!");
  55.          if(!thitu(8,rnd(6),"arrow")){
  56.             mksobj_at(WEAPON_SYM, ARROW, u.ux, u.uy);
  57.             fobj->quan = 1;
  58.          }
  59.          break;
  60.       case TRAPDOOR:
  61.          if(!xdnstair) {
  62. pline("A trap door in the ceiling opens and a rock falls on your head!");
  63. if(uarmh) pline("Fortunately, you are wearing a helmet!");
  64.          losehp(uarmh ? 2 : d(2,10),"falling rock");
  65.          } else {
  66.              register int newlevel = dlevel + 1;
  67.             while(!rn2(4) && newlevel < 29)
  68.                newlevel++;
  69.             pline("A trap door opens up under you!");
  70.             if(Levitation || u.ustuck) {
  71.              pline("For some reason you don't fall in.");
  72.                break;
  73.             }
  74.  
  75.             goto_level(newlevel, FALSE);
  76.          }
  77.          break;
  78.       case DART_TRAP:
  79.          pline("A little dart shoots out at you!");
  80.          if(thitu(7,rnd(3),"little dart")) {
  81.              if(!rn2(6))
  82.             poisoned("dart","poison dart");
  83.          } else {
  84.             mksobj_at(WEAPON_SYM, DART, u.ux, u.uy);
  85.             fobj->quan = 1;
  86.          }
  87.          break;
  88.         case TELEP_TRAP:
  89.             if(trap->gflag & ONCE) {
  90.                 deltrap(trap);
  91.                 newsym(u.ux,u.uy);
  92.                 vtele();
  93.             } else {
  94.                 newsym(u.ux,u.uy);
  95.                 tele();
  96.             }
  97.             break;
  98.       case PIT:
  99.          if(Levitation) {
  100.             pline("A pit opens up under you!");
  101.             pline("You don't fall in!");
  102.             break;
  103.          }
  104.          pline("You fall into a pit!");
  105.          u.utrap = rn1(6,2);
  106.          u.utraptype = TT_PIT;
  107.          losehp(rnd(6),"fall into a pit");
  108.          selftouch("Falling, you");
  109.          break;
  110.       default:
  111.          pline("You hit a trap of type %d",trap->gflag);
  112.          impossible();
  113.       }
  114.    }
  115. }
  116.  
  117. mintrap(mtmp) register struct monst *mtmp; {
  118.    register struct gen *gen = g_at(mtmp->mx, mtmp->my, ftrap);
  119.    register int wasintrap = mtmp->mtrapped;
  120.  
  121.    if(!gen) {
  122.       mtmp->mtrapped = 0;   /* perhaps teleported? */
  123.    } else if(wasintrap) {
  124.       if(!rn2(40)) mtmp->mtrapped = 0;
  125.    } else {
  126.         register int tt = (gen->gflag & TRAPTYPE);
  127.        int in_sight = cansee(mtmp->mx,mtmp->my);
  128.        extern char mlarge[];
  129.        if(mtmp->mtrapseen & (1 << tt)) {
  130.       /* he has been in such a trap - perhaps he escapes */
  131.       if(rn2(4)) return(0);
  132.        }
  133.        mtmp->mtrapseen |= (1 << tt);
  134.        switch (tt) {
  135.       case BEAR_TRAP:
  136.          if(strchr(mlarge, mtmp->data->mlet)) {
  137.             if(in_sight)
  138.               pline("%s is caught in a bear trap!",
  139.                Monnam(mtmp));
  140.             else
  141.               if(mtmp->data->mlet == 'o')
  142.              pline("You hear the roaring of an angry bear!");
  143.             mtmp->mtrapped = 1;
  144.          }
  145.          break;
  146.       case PIT:
  147.          if(!strchr("Eyw", mtmp->data->mlet)) {
  148.             mtmp->mtrapped = 1;
  149.             if(in_sight)
  150.               pline("%s falls in a pit!", Monnam(mtmp));
  151.          }
  152.          break;
  153.       case SLP_GAS_TRAP:
  154.          if(!mtmp->msleep && !mtmp->mfroz) {
  155.             mtmp->msleep = 1;
  156.             if(in_sight)
  157.               pline("%s suddenly falls asleep!",
  158.                Monnam(mtmp));
  159.          }
  160.          break;
  161.       case TELEP_TRAP:
  162.          rloc(mtmp);
  163.          if(in_sight && !cansee(mtmp->mx,mtmp->my))
  164.             pline("%s suddenly disappears!",
  165.                Monnam(mtmp));
  166.          break;
  167.       case ARROW_TRAP:
  168.          if(in_sight) {
  169.             pline("%s is hit by an arrow!",
  170.                Monnam(mtmp));
  171.          }
  172.          mtmp->mhp -= 3;
  173.          break;
  174.       case DART_TRAP:
  175.          if(in_sight) {
  176.             pline("%s is hit by a dart!",
  177.                Monnam(mtmp));
  178.          }
  179.          mtmp->mhp -= 2;
  180.          /* not mondied here !! */
  181.          break;
  182.       case TRAPDOOR:
  183.          if(!xdnstair) {
  184.             mtmp->mhp -= 10;
  185.             if(in_sight)
  186. pline("A trap door in the ceiling opens and a rock hits %s!", monnam(mtmp));
  187.             break;
  188.          }
  189.          if(mtmp->data->mlet != 'w'){
  190.             fall_down(mtmp);
  191.             if(in_sight)
  192.       pline("Suddenly, %s disappears out of sight.", monnam(mtmp));
  193.             return(2);   /* no longer on this level */
  194.          }
  195.          break;
  196.       case PIERC:
  197.          break;
  198.       default:
  199.          pline("Some monster encountered an impossible trap.");
  200.          impossible();
  201.        }
  202.    }
  203.    return(mtmp->mtrapped);
  204. }
  205.  
  206. selftouch(arg) char *arg; {
  207.    if(uwep && uwep->otyp == DEAD_COCKATRICE){
  208.       pline("%s touch the dead cockatrice.", arg);
  209.       pline("You turn to stone.");
  210.       killer = objects[uwep->otyp].oc_name;
  211.       done("died");
  212.    }
  213. }
  214.  
  215. float_up(){
  216.    if(u.utrap) {
  217.       if(u.utraptype == TT_PIT) {
  218.          u.utrap = 0;
  219.          pline("You float up, out of the pit!");
  220.       } else {
  221.          pline("You float up, only your leg is still stuck.");
  222.       }
  223.    } else
  224.       pline("You start to float in the air!");
  225. }
  226.  
  227. float_down(){
  228.    register struct gen *trap;
  229.    pline("You float gently to the ground.");
  230.    if(trap = g_at(u.ux,u.uy,ftrap))
  231.         switch(trap->gflag & TRAPTYPE) {
  232.         case PIERC:
  233.             break;
  234.         case TRAPDOOR:
  235.             if(!xdnstair || u.ustuck) break;
  236.             /* fall into next case */
  237.         default:
  238.             dotrap(trap);
  239.         }
  240.    pickup();
  241. }
  242.  
  243. vtele() {
  244. #define    VAULT    6
  245.     register struct mkroom *croom;
  246.     for(croom = &rooms[0]; croom->hx >= 0; croom++)
  247.         if(croom->rtype == VAULT) {
  248.         register int x,y;
  249.  
  250.         x = rn2(2) ? croom->lx : croom->hx;
  251.         y = rn2(2) ? croom->ly : croom->hy;
  252.         if(teleok(x,y)) {
  253.             teleds(x,y);
  254.             return;
  255.         }
  256.          }
  257.     tele();
  258. }
  259.  
  260. tele() {
  261.     extern coord getpos();
  262.     coord cc;
  263.     register int nux,nuy;
  264.  
  265.    if(Teleport_control) {
  266.       pline("To what position do you want to be teleported?");
  267.       cc = getpos(1, "the desired position"); /* 1: force valid */
  268.       /* possible extensions: introduce a small error if
  269.          magic power is low; allow transfer to solid rock */
  270.       if(teleok(cc.x, cc.y)){
  271.             teleds(cc.x, cc.y);
  272.             return;
  273.       }
  274.       pline("Sorry ...");
  275.    }
  276.    do {
  277.       nux = rnd(COLNO-1);
  278.       nuy = rn2(ROWNO);
  279.    } while(!teleok(nux, nuy));
  280.  
  281.     teleds(nux, nuy);
  282. }
  283.  
  284. teleds(nux, nuy)
  285. register int nux,nuy;
  286. {
  287.    if(Punished) unplacebc();
  288.    unsee();
  289.    u.utrap = 0;
  290.    u.ustuck = 0;
  291.    u.ux = nux;
  292.    u.uy = nuy;
  293.    setsee();
  294.    if(Punished) placebc(1);
  295.    if(u.uswallow){
  296.       u.uswldtim = u.uswallow = 0;
  297.       docrt();
  298.    }
  299.    nomul(0);
  300.    (void) inshop();
  301.    pickup();
  302.    if(!Blind) read_engr_at(u.ux,u.uy);
  303. }
  304.  
  305. teleok(x,y) register int x,y; {
  306.    return( isok(x,y) && levl[x][y].typ > DOOR && !m_at(x,y) &&
  307.       !sobj_at(ENORMOUS_ROCK,x,y) && !g_at(x,y,ftrap)
  308.    );
  309.    /* Note: gold is permitted (because of vaults) */
  310. }
  311.  
  312. dotele() {
  313.     extern char pl_character[];
  314.  
  315.     if(
  316. #ifdef WIZARD
  317.        !wizard &&
  318. #endif WIZARD
  319.               (!Teleportation || u.ulevel < 6 ||
  320.             (pl_character[0] != 'W' && u.ulevel < 10))) {
  321.         pline("You are not able to teleport at will.");
  322.         return(0);
  323.     }
  324.     if(u.uhunger <= 100 || u.ustr < 6) {
  325.         pline("You miss the strength for a teleport spell.");
  326.         return(1);
  327.     }
  328.     tele();
  329.     morehungry(100);
  330.     return(1);
  331. }
  332.  
  333. placebc(attach) int attach; {
  334.    if(!uchain || !uball){
  335.       pline("Where are your chain and ball??");
  336.       impossible();
  337.       return;
  338.    }
  339.    uball->ox = uchain->ox = u.ux;
  340.    uball->oy = uchain->oy = u.uy;
  341.    if(attach){
  342.       uchain->nobj = fobj;
  343.       fobj = uchain;
  344.       if(!carried(uball)){
  345.          uball->nobj = fobj;
  346.          fobj = uball;
  347.       }
  348.    }
  349. }
  350.  
  351. unplacebc(){
  352.    if(!carried(uball)){
  353.       freeobj(uball);
  354.       unpobj(uball);
  355.    }
  356.    freeobj(uchain);
  357.    unpobj(uchain);
  358. }
  359.  
  360. level_tele() {
  361. register int newlevel = 5 + rn2(20);   /* 5 - 24 */
  362.    if(dlevel == newlevel)
  363.       if(!xdnstair) newlevel--; else newlevel++;
  364.    goto_level(newlevel, FALSE);
  365. }
  366.  
  367.